package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.pojo.order.Order;
import com.qingcheng.pojo.user.Address;
import com.qingcheng.service.order.OrderService;
import com.qingcheng.service.user.AddressService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Title: OrderController
 * @Description:
 * @Auther:
 * @Version: 1.0
 * @create 2021/10/14 9:33
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Reference
    private AddressService addressService;

    @Reference
    private OrderService orderService;


    @RequestMapping("getAddressList")
    public List<Address> getAddressList(){
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
       return  addressService.getAddressList(name);
    }

    @RequestMapping("/submitOrder")
    public Map submitOrder(@RequestBody Order order){
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        System.out.println(orderService);
        return orderService.submitOrder(name,order);

    }
}
